package com.ebs.md.fxmonitor.marketmonitor.esper;

/**
 /**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/esper/SelfMatchingBasicFactStatement.java $
 *  $Revision: #5 $  $Change: 114924 $  $DateTime: 2012/09/13 09:11:55 $  $Author: Aviad.Yosef $
 */

import com.ebs.md.container.esper.AbsStatement;
import com.ebs.md.fxmonitor.marketmonitor.config.ISelfMatchingConfig;
import com.ebs.md.fxmonitor.marketmonitor.config.ISelfMatchingConfig.EAggressiveOrderType;


public class SelfMatchingBasicFactStatement
extends AbsStatement<ISelfMatchingConfig>
{
	protected final static long esper_time_period_self_matching = 2;

	@Override
	protected String createEplExpression() {
		boolean isAny = true;
		
		if (EAggressiveOrderType.IOC == config.getAggressiveOrderType() ) {
			isAny = false;
		}
		
		String str =
		String.format(eplExpressionText
						, config.getName()                   //1. configuration name.
						
						, esper_time_period_self_matching    //2. Deal  .win:ext_timed(timestamp, %d seconds)  
						, esper_time_period_self_matching    //3.       .win:ext_timed(timestamp, %d seconds)  
						, esper_time_period_self_matching    //4.       .win:ext_timed(timestamp, %d seconds)  
						
						//5. region
						, getRegion()          

						//6. if configuration is set to ANY  then we always return true here.
						, isAny                              
						
						//7. ( true  = %s and hit.amount = deal.amount)   /* if   configuration is set to EQUAL */
						, config.getIsAggressiveVsPassiveOrderSizeEquals()  
						
						//8. ( false = %s and hit.amount <> deal.amount ) /* else configuration is set to NOT EQUAL */
						, config.getIsAggressiveVsPassiveOrderSizeEquals()  

						//9. and obcAggressive.timestamp - obcPassive.timestamp <= %d 
						, config.getTimeToMatchThreshold()   
				      );
		
		logger.info("createEplExpression: " + str);

		return str;
	}
	
}
